package com.liyujie.networkrequest.ui.management;

import android.os.Bundle;
import android.view.View;

import androidx.lifecycle.ViewModelProvider;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.SPUtils;
import com.liyujie.networkrequest.R;
import com.liyujie.networkrequest.databinding.ActivityBackstageBinding;
import com.liyujie.networkrequest.pop.ServerAddressSettingPopup;
import com.liyujie.networkrequest.ui.BaseActivity;
import com.liyujie.networkrequest.ui.management.serialport.SerialPortActivity;
import com.liyujie.networkrequest.utils.InitializeUtils;
import com.liyujie.networkrequest.views.NoDoubleClickListener;
import com.liyujie.networkrequest.views.passlibrary.PayPassDialog;
import com.liyujie.networkrequest.views.passlibrary.PayPassView;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.enums.PopupAnimation;


/**
 * 后台管理
 */
public class BackstageActivity extends BaseActivity<ActivityBackstageBinding> {



    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_backstage;

    }


    @Override
    public void initView() {
        super.initView();
        setWhiteActionBarStyle("后台管理");
    }


    @Override
    protected void onStart() {
        super.onStart();

    }

    @Override
    public void initData() {
        super.initData();

    }


    @Override
    public void initViewObservable() {
        super.initViewObservable();
        /**
         *  串口设置
         */
        binding.synchronizer.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                /**
                 * 串口管理
                 */
                ActivityUtils.startActivity(SerialPortActivity.class);
            }
        });
        /**
         *  服务器地址设置
         */
        binding.ServerAddressSetting.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                ServerAddressSettingPopup mServerAddressSettingPopup = new ServerAddressSettingPopup(mContext);
                new XPopup.Builder(ActivityUtils.getTopActivity())
                        .popupAnimation(PopupAnimation.ScaleAlphaFromCenter)
                        .autoOpenSoftInput(false)
                        .asCustom(mServerAddressSettingPopup)
                        .show();
            }
        });

        /**
         * 管理员密码修改
         */
        binding.PasswordChange.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                PayPassDialog payPassDialog = new PayPassDialog(mContext);
                payPassDialog.getPayViewPass().setPayClickListener(new PayPassView.OnPayClickListener() {
                    @Override
                    public void onPassFinish(String password) {
                        //关闭回调
                        payPassDialog.dismiss();
                        SPUtils.getInstance().put("managementPassword",password);
                        InitializeUtils.getDefaultMaker().show("管理员密码修改成功");
                    }

                    @Override
                    public void onPayClose() {
                        //关闭回调
                        payPassDialog.dismiss();
                    }
                });
                if(null != payPassDialog){
                    payPassDialog.show();
                }
            }
        });
        /**
         *  关闭程序
         */
        binding.CloseProgram.setOnClickListener(new NoDoubleClickListener() {
            @Override
            protected void onNoDoubleClick(View v) {
                ActivityUtils.finishAllActivities();
                try {
                    // 关闭整个应用程序
                    System.exit(0);
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        });
    }
}
